package com.tencent.wework.demo

import android.os.SystemClock
import com.tencent.wework.list.easy.EasyRepository
import kotlin.concurrent.thread

/**
 * Created by huangwei on 2019/5/28.
 */
object DemoRepository:EasyRepository<List<ItemData>>(){

    override fun requestData(callback: (data: List<ItemData>) -> Unit) {
        thread {
            val list = listOf<ItemData>(
                ItemData("aaa", "aaaaaa"),
                ItemData("bbb", "bbbbbb"),
                ItemData("ccc", "cccccc"),
                ItemData("ddd", "dddddd"),
                ItemData("eee", "eeeeee"),
                ItemData("fff", "ffffff"),
                ItemData("ggg", "gggggg"),
                ItemData("hhh", "hhhhhh"),
                ItemData("iii", "iiiiii"),
                ItemData("jjj", "jjjjjj"),
                ItemData("kkk", "kkkkkk"),
                ItemData("lll", "llllll"),
                ItemData("mmm", "mmmmmm")
            )

            callback(list)
        }
    }

    override fun loadMoreData(offset: Any?, callback: (data: List<ItemData>) -> Unit) {
        thread {
            SystemClock.sleep(2000)
            val list = listOf<ItemData>(
                ItemData("more${offset}1", "aaaaaa"),
                ItemData("more${offset}2", "aaaaaa"),
                ItemData("more${offset}3", "aaaaaa"),
                ItemData("more${offset}4", "aaaaaa")
                )
                callback(if(offset as? Int?:0>15) emptyList() else list)
        }
    }
}